package com.pcitc.springbootmybatis.mapper;

import com.pcitc.springbootmybatis.enums.UserSexEnum;
import com.pcitc.springbootmybatis.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Select("select * from users")
    @Results({
            @Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
            @Result(property = "nickName", column = "nick_name"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "passWord", column = "pass_word")
    })
    List<User> getAll();

    @Select("select * from users where id = #{id}")
    @Results({
            @Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
            @Result(property = "nickName", column = "nick_name"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "passWord", column = "pass_word")
    })
    User getOne(Long id);

    @Insert("insert into users(user_name,pass_word,user_sex) values(#{userName},#{passWord},#{userSex})")
    void insert(User user);

    @Update("update users set user_name=#{userName},nick_name=#{nickName} where id = #{id}")
    void update(User user);

    @Delete("delete from users where id = #{id}")
    void delete(Long id);
}
